<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
    <el-form-item label="商户" prop="deptId">
      <el-input
          v-model="queryParams.deptId"
          placeholder="请选择商户"
          clearable
      />
    </el-form-item>
    <el-form-item label="按年查看" prop="year" >
      <el-date-picker
          v-model="queryParams.year"
          type="year"
          placeholder="请选择"
          value-format="YYYY"
          clearable
      />
    </el-form-item>
    <el-form-item label="按月查看" prop="month">
      <el-date-picker
          v-model="queryParams.month"
          type="month"
          placeholder="请选择"
          value-format="YYYY-MM"
          clearable
      />
    </el-form-item>
    <el-form-item label="按日期" prop="day">
      <el-date-picker
          clearable
          v-model="queryParams.day"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择">
      </el-date-picker>
    </el-form-item>
    <el-form-item label="截至日期" prop="endDate">
      <el-date-picker
          clearable
          v-model="queryParams.endDate"
          type="date"
          value-format="YYYY-MM-DD"
          placeholder="请选择">
        </el-date-picker>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
      <el-button icon="Refresh" @click="reset">重置</el-button>
    </el-form-item>
  </el-form>
  <el-table  :data="orderList" >
    <el-table-column label="统计日期" align="center" prop="payDate" />
    <el-table-column label="商户名称" align="center" prop="deptName" />
    <el-table-column label="统计金额" align="center" prop="totalAmount" />
    <el-table-column label="使用车次" align="center" prop="vehicleCount" />
    <el-table-column label="用户数量" align="center" prop="userCount" />
  </el-table>
  <pagination
      v-show="total>0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
  />
  </div>
</template>

<script setup name="Stt">
import { orderStatByMarch } from "@/api/order/stt";

const orderList = ref([]);
const showSearch = ref(true);
const total = ref(0);

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    deptId: null,
    year: null,
    month: null,
    day: null,
    endData: null,
    startData: null,
  },
})

const { queryParams } = toRefs(data);
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  if(queryParams.value.endData!=null){
    if (queryParams.value.startData==null){
      if (queryParams.value.day!=null){
        queryParams.value.startData=queryParams.value.day;
        queryParams.value.day = null;

      }else {
        queryParams.value.startData=queryParams.value.endData
      }
    }
  }
  getList();
}
function getList() {
  orderStatByMarch(queryParams.value).then((res) => {
    orderList.value = res.rows;
    total.value = res.total;
  });
}
// 表单重置
function reset() {
  queryParams.value = {
    pageNum: 1,
    pageSize: 10,
    deptId: null,
    year: null,
    month: null,
    day: null,
    endData: null,
    startData: null,
  };
}
getList();
</script>
